package com.itheima.day11.otherio.test1;

import java.io.*;
import java.nio.charset.Charset;

/*
    转换流
 */
public class Test {
    public static void main(String[] args) throws IOException {
        // method1();

        // 转换流
         method2();

        // JDK11之后
        FileReader fr = new FileReader("myCode\\src\\com\\itheima\\day11\\f.txt", Charset.forName("GBK"));
        int len;
        while ((len = fr.read()) != -1){
            System.out.print((char)len);
        }
    }

    private static void method2() throws IOException {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("myCode\\src\\com\\itheima\\day11\\f.txt"),"UTF-8");
        osw.write("apex捍卫者，apex猎杀者,halou，爱你摸摸哒");
        osw.close();

        InputStreamReader isr = new InputStreamReader(new FileInputStream("myCode\\src\\com\\itheima\\day11\\f.txt"),"GBK");
        int len;
        while((len = isr.read()) != -1){
            System.out.print((char)len);
        }
        isr.close();
    }


    private static void method1() throws IOException {
        FileReader fr = new FileReader("C:\\Users\\34564\\Desktop\\shabi.txt");
        int len;
        while ((len = fr.read()) != -1){
            System.out.println((char)len);
        }
        fr.close();
    }
}
